﻿using MediatR;
using Sale.Api.Application.Command.CType;
using Sale.Domain;
using Sale.ErrorCode;
using Sale.Infrastructure.Interface;

namespace Sale.Api.Application.Handler.CType
{
    public class GetCTypeHandler : IRequestHandler<GetCTypeCommand, ApiResult<List<CTypeModel>>>
    {
        private readonly IBaseRepository<CTypeModel> ctypeRepo;
        private readonly ILogger<GetCTypeHandler> logger;

        public GetCTypeHandler(IBaseRepository<CTypeModel> ctypeRepo,ILogger<GetCTypeHandler> logger)
        {
            this.ctypeRepo = ctypeRepo;
            this.logger = logger;
        }
        public Task<ApiResult<List<CTypeModel>>> Handle(GetCTypeCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<CTypeModel>> result = new ApiResult<List<CTypeModel>>();
            var ctype = ctypeRepo.GetAll();
            result.Code=ApiEnum.OK;
            result.Data = ctype.ToList();
            result.Msg = "客户类型查询成功";
            logger.LogInformation(result.Msg);
            return Task.FromResult(result);
        }
    }
}
